<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .w {
            /* 版心 */
            /* width: 1126px; */
            width: 1226px;
            margin: 0 auto;
        }

        html {
            scroll-behavior: smooth;
        }

        .header {
            height: 200px;
            background: grey;
        }

        .wrapNav {
            width: 100%;
            background-color: grey;
            /*
            了解 
            粘性定位:  吸顶效果的
                (1) 盒子顶部没有移出 窗口(包裹该盒子的父元素)之前,标准文档流,移出之后会变为固定定位
            */
            /* position:sticky;
            top: 0;
            left: 0; */
            /* position: none; */
        }

        .nav {
            background: pink;
            height: 45px;
        }

        .banner {
            height: 300px;
            background-color: red;
        }

        .main .part {
            height: 400px;
            line-height: 400px;
            text-align: center;
            border: 1px solid #333;
        }

        .footer {
            height: 500px;
            background-color: grey;
        }

        .tips {
            width: 100%;
            line-height: 45px;
            text-align: center;
            background-color: rgba(125, 255, 255, 0.6);
            position: fixed;
            bottom: 0;
            left: 0;
            display: none;
            /* display: block; */
        }
    </style>
</head>

<body>
    <!--  -->
    <div class="header w"></div>
    <div class="wrapNav">
        <div class="nav w">
            <!-- 锚链接 -->
            <a href="#live">直播</a>
            <a href="#ani">动画</a>
            <a href="#drama">番剧</a>
            <a href="#chAni">国漫</a>
            <a href="#music">音乐</a>
            <a href="#sports">运动</a>
            <!--  # 默认返回当前页面的顶部 -->
            <a href="#">返回顶部</a>

            <!-- a 默认跳转当前页  => 刷新页面 -->
            <a href="">刷新</a>
        </div>
    </div>
    <div class="banner w"></div>
    <div class="main w">
        <!-- 锚标记 -->
        <div id="live" class="part">直播</div>
        <div id="ani" class="part">动画</div>
        <div id="drama" class="part">番剧</div>
        <div id="chAni" class="part">国漫</div>
        <div id="music" class="part">音乐</div>
        <div id="sports" class="part">运动</div>
    </div>
    <div class="footer w"></div>
    <div class="tips">到达底部</div>
</body>
<script>
    // 1. 导航栏吸顶效果
    // 2. 判断滚动条是否到达底部  =>显示tips  0.5s后消失
    var wrapNav = document.getElementsByClassName("wrapNav")[0];
    var tips = document.getElementsByClassName("tips")[0];
    console.log(wrapNav);

    window.onscroll = function () {
        var scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
        var clientHeight = document.documentElement.clientHeight || document.body.clientHeight;
        var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
        var bottoms = scrollHeight - clientHeight;
        console.log(scrollTop, scrollHeight, clientHeight, bottoms);
        if (scrollTop >= 200) {
            wrapNav.style.position = "fixed";
            wrapNav.style.top = "0";
            wrapNav.style.left = "0";
        } else {
            wrapNav.style.position = "static";
        }
        if (scrollTop >= bottoms-1) {
            tips.style.display = "block";
            setTimeout(function () {
                tips.style.display = "none";
            }, 500)
        } else {
            tips.style.display = "none";

        }
    }

    // 文档的可视宽高
    // 文档的实际宽高
    // 滚动条距离页面顶部的位置

</script>

</html>